//
//  WHlifeFees.m
//  WHstoreItemProtect
//
//  Created by wztx on 2017/11/6.
//  Copyright © 2017年 sdwh.com. All rights reserved.
//

#import "WHlifeFees.h"

#import "LWGroupItem.h"
#import "LWSettingItem.h"


@interface WHlifeFees ()

//当前界面的数据源 用来存储分组模型
@property (nonatomic ,strong) NSMutableArray *groupArray;

@end

@implementation WHlifeFees

#pragma MARK - 懒加载
- (NSMutableArray *)groupArray
{
    if (!_groupArray) {
        _groupArray = [NSMutableArray array];
    }
    return _groupArray;
}
//构造
- (instancetype)init
{
    return [self initWithStyle:UITableViewStyleGrouped];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupUI];
    [self group1];
    [self group2];
    [self group3];
    [self group4];
    
}

#pragma MARK - UI
- (void)setupUI
{
    self.title = @"生活缴费";
    UIBarButtonItem *backBtnItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"返回"] style:UIBarButtonItemStylePlain target:self action:@selector(popClick)];
    self.navigationItem.leftBarButtonItem = backBtnItem;
}
#pragma MARK - POP
- (void)popClick
{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma MARK - 条目分组
- (void)group1
{
    LWGroupItem *group0 = [[LWGroupItem alloc] init];
    LWSettingItem *item = [LWSettingItem itemWithTitle:@"话费充值" icon:@"huafeichongzhi"];
    group0.itemsArray = @[item];
    [self.groupArray addObject:group0];
    
}
- (void)group2
{
    LWGroupItem *group0 = [[LWGroupItem alloc] init];
    LWSettingItem *item = [LWSettingItem itemWithTitle:@"加油卡充值" icon:@"jiayoukachongzhi"];
    group0.itemsArray = @[item];
    [self.groupArray addObject:group0];
    
}
- (void)group3
{
    LWGroupItem *group0 = [[LWGroupItem alloc] init];
    LWSettingItem *item = [LWSettingItem itemWithTitle:@"违章查询" icon:@"weizhangchaxuan"];
    group0.itemsArray = @[item];
    [self.groupArray addObject:group0];
    
}
- (void)group4
{
    LWGroupItem *group0 = [[LWGroupItem alloc] init];
    LWSettingItem *item = [LWSettingItem itemWithTitle:@"流量充值" icon:@"liuliangchongzhi"];
    group0.itemsArray = @[item];
    [self.groupArray addObject:group0];
    
}
/**
 *  返回有多少组的代理方法
 */
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return self.groupArray.count;
}

/**
 *  返回每组有多少行的代理方法
 */
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    LWGroupItem *group = self.groupArray[section];
    return group.itemsArray.count;
}

/**
 *  返回每一行Cell的代理方法
 */
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *ID = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell  = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    LWGroupItem *group = self.groupArray[indexPath.section];
    LWSettingItem *item = group.itemsArray[indexPath.row];
    cell.textLabel.text = item.title;
    cell.imageView.image = [UIImage imageNamed:item.icon];
    return cell;
}
/**
 *  选中每一行Cell的代理方法
 */
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        NSLog(@"话费");
    }else if (indexPath.section == 1)
    {
        NSLog(@"加油卡");
    }else if (indexPath.section == 2)
    {
        NSLog(@"违章");
    }else if (indexPath.section == 3)
    {
        NSLog(@"流量");
    }
}

@end
